package com.taotao.callback;


import com.taotao.service.RegisterService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

/**
 * springboot 注意 是正常停止的情况下，则
 * 会发送请求到 服务注册中心 删除该ip和端口
 */
public class CloseCallbackImpl implements ApplicationListener<ContextClosedEvent> {
    private static final Log log = LogFactory.getLog(CloseCallbackImpl.class);
    @Autowired
    private RegisterService registerService;

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        log.info("service client stop");
        // 1.发送rest请求给我们 服务 注册中心 删除该ip和端口
        registerService.remove();
    }

}